<style lang="scss" scoped>
	.store {
		background-color: #fafafa;
	}

	.navs-box {
		position: fixed;
		top: 0;
		left: 0;
		z-index: 999;

		.navs-header {
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			align-items: flex-end;
			width: 750upx;
			height: 150upx;

			&.navs-header-actived {
				background-color: #FFFFFF;
				border-bottom: 1upx solid #eee;
			}

			.nav-img {
				width: 40upx;
				height: 40upx;
				background-color: rgba($color: #FFFFFF, $alpha: 0.01);
				padding: 30upx 0 20upx 44upx;
			}
		}
	}

	.child-navs {
		position: fixed;
		top: 151upx;
		left: 0;
		z-index: 999;
		width: 750upx;
		height: 100%;
		background-color: #FFFFFF;

		.cnavs-box {
			width: 700upx;
			margin-left: 25upx;
			margin-top: 50upx;
			height: 400upx;
			display: flex;
			flex-direction: row;
			flex-wrap: wrap;
			justify-content: flex-start;
			align-items: flex-start;
			align-content: flex-start;

			.cnav-one {
				width: 150upx;
				height: 150upx;
				background-color: #eee;
				border-radius: 10upx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				margin :20upx 10upx 20upx 16upx;

				.cnav-img {
					width: 40upx;
					height: 40upx;
				}

				.name {
					width: 150upx;
					font-size: 24upx;
					margin-top: 20upx;
					color: #001432;
					text-align: center;
				}
			}
		}
	}

	.banner-swiper {
		width: 750upx;
		height: 900upx;

		.banner-swiper-img {
			width: 750upx;
			height: 900upx;
		}
	}

	.products {
		margin-top: 100upx;
		margin-left: 35upx;
		width: 680upx;

		.product-img {
			width: 680upx;
			height: 870upx;
			border-radius: 20upx;
			box-shadow: 0 0 5px 0 rgb(188, 188, 188);
		}

		.product-title {
			margin-top: 30upx;
			font-size: 44upx;
		}

		.product-info {
			margin-top: 10upx;
			font-size: 32upx;
			color: #888;
		}

		.product-btn {
			margin-top: 30upx;
			width: 240upx;
			height: 80upx;
			line-height: 80upx;
			text-align: center;
			background-color: #CD2D29;
			border-radius: 20upx;
			color: #FFFFFF;
		}
	}

	.time-shop {
		background-color: #fff;
		margin-top: 100upx;
		border-radius: 20upx;

		.title {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			padding: 50upx 0;

			.left {
				font-size: 42upx;
				margin-left: 35upx;
			}

			.right {
				color: #888;
				font-size: 28upx;
				margin-right: 35upx;
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;
			}
		}

		.list {
			margin-left: 20upx;
			width: 700upx;
			height: 340upx;

			.card {
				width: 220upx;
				height: 340upx;
				padding: 20upx;
				background-color: #eee;
				border-radius: 10upx;
				margin-right: 20upx;

				.product-img {
					border-top-left-radius: 10upx;
					border-top-right-radius: 10upx;
					width: 180upx;
					height: 180upx;
				}

				.title {
					height: 40upx;
					font-size: 28upx;
					line-height: 40upx;
					margin-top: -10upx;
				}

				.price {
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;
					font-size: 24upx;

					.new-price {
						color: #CD2D29;
					}

					.old-price {
						color: #888;
						font-size: 20upx;
						text-decoration: line-through;
					}
				}
			}
		}
	}

	.get-card {
		background-color: #fff;
		margin-top: 100upx;
		border-radius: 20upx;

		.title {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			padding: 50upx 0;

			.left {
				font-size: 42upx;
				margin-left: 35upx;
			}

			.right {
				color: #888;
				font-size: 28upx;
				margin-right: 35upx;
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;
			}
		}

		.list {
			margin-left: 20upx;
			width: 700upx;
			height: 140upx;

			.card {
				width: 220upx;
				height: 120upx;
				padding: 20upx;
				background-color: #fef7f7;
				border-radius: 10upx;
				margin-right: 20upx;
				border: 1px solid #CD2D29;
				position: relative;

				.cleft {
					position: absolute;
					top: 45upx;
					left: -20upx;
					width: 30upx;
					height: 30upx;
					z-index: 999;
					background-color: #fff;
					border: 1px solid #CD2D29;
					border-top-right-radius: 50%;
					border-bottom-right-radius: 50%;
				}

				.cright {
					position: absolute;
					top: 45upx;
					right: -20upx;
					width: 30upx;
					height: 30upx;
					background-color: #fff;
					border: 1px solid #CD2D29;
					border-top-left-radius: 50%;
					border-bottom-left-radius: 50%;
				}

				.cright-up {
					position: absolute;
					top: 45upx;
					right: -22upx;
					width: 20upx;
					height: 32upx;
					background-color: #fff;
				}

				.up {
					color: #CD2D29;
					text-align: center;
					margin-top: -12upx;

					.tag {
						font-size: 24upx;
					}

					.num {
						font-size: 36upx;
					}
				}

				.line {
					height: 1upx;
					background-color: #E7A3A1;
					margin-top: 6upx;
					margin-bottom: 12upx;
					width: 160upx;
					margin-left: 10upx;
				}

				.down {
					text-align: center;
					color: #001432;
					font-size: 20upx;
				}
			}
		}
	}


	.ok-chose {
		background-color: #FFFFFF;
		margin-top: 60upx;
		padding-top: 40upx;
		padding-bottom: 40upx;

		.title {
			margin-top: 0;
			font-size: 44upx;
			text-align: center;
			padding: 20upx 0;
		}

		.puducts {
			width: 680upx;
			margin-top: 40upx;
			margin-left: 40upx;
			display: flex;
			flex-direction: row;
			flex-wrap: wrap;
			justify-content: space-between;
			align-items: center;

			.card {
				width: 330upx;
				height: 500upx;
				background-color: #f9f9f9;
				overflow: hidden;
				position: relative;
				border-radius: 10upx;
				margin-bottom: 40upx;

				.tag {
					position: absolute;
					left: 0;
					top: 0;
					border-top-left-radius: 10upx;
					border-bottom-right-radius: 10upx;
					background-color: #7DBDFF;
					font-size: 20upx;
					padding: 4upx 10upx;
					color: #fff;

					&.cred {
						background-color: #FF7373;
					}

					&.cyellow {
						background-color: #FFB867;
					}
					
					&.cblue{
						background-color: #007abc;
					}
				}

				.like {
					width: 30upx;
					height: 30upx;
					position: absolute;
					top: 20upx;
					right: 20upx;
				}

				.product-img {
					width: 250upx;
					height: 250upx;
					margin: 20upx 0 20upx 50upx;
				}

				.title {
					text-align: center;
					font-size: 28upx;
					height: 110upx;
					width: 290upx;
					margin-left: 20upx;
				}

				.info {
					text-align: center;
					font-size: 20upx;
					color: #999;
					margin-top: 0;
				}

				.price {
					margin-top: 10upx;
					display: flex;
					flex-direction: row;
					justify-content: center;
					align-items: center;

					.new-price {
						font-size: 32upx;
						color: #CD2D29;
					}

					.old-price {
						color: #888;
						font-size: 24upx;
						margin-left: 20upx;
						text-decoration: line-through;
					}
				}
			}
		}
	}

	.ok-other {
		background-color: #FFFFFF;
		margin-top: 60upx;
		padding-bottom: 80upx;
		padding-top: 40upx;

		.title {
			padding: 20upx 0;
			font-size: 44upx;
			text-align: center;
		}

		.puducts {
			width: 680upx;
			padding-top: 40upx;
			margin-left: 40upx;
			display: flex;
			flex-direction: row;
			flex-wrap: wrap;
			justify-content: space-between;
			align-items: center;

			.card {
				width: 330upx;
				height: 500upx;
				background-color: #f9f9f9;
				overflow: hidden;
				position: relative;
				border-radius: 10upx;

				.tag {
					position: absolute;
					left: 0;
					top: 0;
					border-top-left-radius: 10upx;
					border-bottom-right-radius: 10upx;
					background-color: #7DBDFF;
					font-size: 20upx;
					padding: 4upx 10upx;
					color: #fff;

					&.cred {
						background-color: #FF7373;
					}

					&.cyellow {
						background-color: #FFB867;
					}
					&.cblue{
						background-color: #007abc;
					}
				}

				.product-img {
					width: 250upx;
					height: 250upx;
					margin: 20upx 0 20upx 50upx;
				}

				.title {
					text-align: center;
					font-size: 28upx;
					height: 110upx;
					width: 290upx;
					margin-left: 20upx;
				}

				.info {
					text-align: center;
					font-size: 20upx;
					color: #999;
					margin-top: 0;
				}

				.price {
					margin-top: 10upx;
					display: flex;
					flex-direction: row;
					justify-content: center;
					align-items: center;

					.new-price {
						font-size: 32upx;
						color: #CD2D29;
					}

					.old-price {
						color: #888;
						font-size: 24upx;
						margin-left: 20upx;
						text-decoration: line-through;
					}
				}
			}
		}
	}
</style>
<template>
	<view class="store">
		<!-- 顶部导航 -->
		<cover-view class="navs-box">
			<cover-view class="navs-header" v-if="navBarShowTag">
				<cover-image class="nav-img" src="../static/store/1-1.png" v-if="!navBarChildShowTag" mode="aspectFit" @tap="openChildNav" />
				<cover-image class="nav-img" src="../static/store/11.png" v-else mode="aspectFit" @tap="closeChildNav" />
				<cover-image class="nav-img" src="../static/store/2-2.png" v-if="allLinks.display.index" mode="aspectFit" @tap="gotoStoreWebView(allLinks.urls.index)" />
			</cover-view>
			<cover-view class="navs-header navs-header-actived" v-else>
				<cover-image class="nav-img" src="../static/store/1.png" v-if="!navBarChildShowTag" mode="aspectFit" @tap="openChildNav" />
				<cover-image class="nav-img" src="../static/store/11.png" v-else mode="aspectFit" @tap="closeChildNav" />
				<cover-image class="nav-img" src="../static/store/2.png" v-if="allLinks.display.index" mode="aspectFit" @tap="gotoStoreWebView(allLinks.urls.index)" />
			</cover-view>
		</cover-view>
		<cover-view class="child-navs" v-if="navBarChildShowTag">
			<cover-view class="cnavs-box">
				<cover-view class="cnav-one" v-if="allLinks.display.categoryList" @tap="gotoStoreWebView(allLinks.urls.categoryList[0])">
					<cover-image class="cnav-img" src="../static/store/3.png" mode="aspectFit" />
					<cover-view class="name">分类</cover-view>
				</cover-view>
				<cover-view class="cnav-one" v-if="allLinks.display.order_list" @tap="gotoStoreWebView(allLinks.urls.order_list[0])">
					<cover-image class="cnav-img" src="../static/store/4.png" mode="aspectFit" />
					<cover-view class="name">订单</cover-view>
				</cover-view>
				<cover-view class="cnav-one" v-if="allLinks.display.collect_list" @tap="gotoStoreWebView(allLinks.urls.collect_list[0])">
					<cover-image class="cnav-img" src="../static/store/5.png" mode="aspectFit" />
					<cover-view class="name">心愿单</cover-view>
				</cover-view>
				<cover-view class="cnav-one" v-if="allLinks.display.coupon" @tap="gotoStoreWebView(allLinks.urls.coupon[0])">
					<cover-image class="cnav-img" src="../static/store/6.png" mode="aspectFit" />
					<cover-view class="name">优惠券</cover-view>
				</cover-view>
				<cover-view class="cnav-one" v-if="allLinks.display.coupon_list" @tap="gotoStoreWebView(allLinks.urls.coupon_list[0])">
					<cover-image class="cnav-img" src="../static/store/7.png" mode="aspectFit" />
					<cover-view class="name">领券中心</cover-view>
				</cover-view>
				<cover-view class="cnav-one" v-if="allLinks.display.rocde_list.length>0" @tap="gotoStoreWebView(allLinks.urls.rocde_list[0])">
					<cover-image class="cnav-img" src="../static/store/8.png" mode="aspectFit" />
					<cover-view class="name">R码</cover-view>
				</cover-view>
				<cover-view class="cnav-one" v-if="allLinks.display.address_list" @tap="gotoStoreWebView(allLinks.urls.address_list[0])">
					<cover-image class="cnav-img" src="../static/store/9.png" mode="aspectFit" />
					<cover-view class="name">地址管理</cover-view>
				</cover-view>
				<cover-view class="cnav-one" v-if="allLinks.display.chat" @tap="gotoStoreWebView(allLinks.urls.chat[0], 'other')">
					<cover-image class="cnav-img" src="../static/store/10.png" mode="aspectFit" />
					<cover-view class="name">客服</cover-view>
				</cover-view>
			</cover-view>
		</cover-view>

		<!-- 置顶轮播图 -->
		<swiper class="banner-swiper" :indicator-dots="true" indicator-color="#AAAAAA" indicator-active-color="#FFFFFF"
		 :autoplay="true" :interval="2500" :duration="500">
			<swiper-item v-for="item in allInfos.banner" :key="item.id">
				<image class="banner-swiper-img" :src="item.ad_code" mode="aspectFill" @tap="gotoStoreWebView(item.ad_link)" />
			</swiper-item>
		</swiper>


		<!-- 商品选项卡-->
		<view v-for="(item, index) in allInfos.productlist" :key="index" class="products">
			<image :src="item.ad_code" mode="aspectFill" class="product-img"  @tap="gotoStoreWebView(item.ad_link)"/>
			<view class="product-title">{{item.ad_title}}</view>
			<view class="product-info">{{item.ad_subtitle}}</view>
			<view class="product-btn" @tap="gotoStoreWebView(item.ad_link)">立即选购</view>
		</view>

		<!-- 限时购 -->
		<!-- <view class="time-shop">
			<view class="title">
				<view class="left">限时购</view>
				<view class="right">
					<view>更多</view>
					<u-icon name="arrow-right" size="30" color="#999" />
				</view>
			</view>
			<view class="list">
				<swiper class="list" :indicator-dots="false" :autoplay="true" :interval="2500" :duration="500"
				 :display-multiple-items="3">
					<swiper-item v-for="(item, index) in tshopList" :key="index">
						<view class="card">
							<image :src="item.img" mode="aspectFit" class="product-img" />
							<view class="title">{{item.title}}</view>
							<view class="price">
								<view class="new-price">{{item.newPrice}}</view>
								<view class="old-price">{{item.oldPrice}}</view>
							</view>
						</view>
					</swiper-item>
				</swiper>
			</view>
		</view> -->
		<!-- 领劵中心 -->
		<!-- <view class="get-card">
			<view class="title">
				<view class="left">领券中心</view>
				<view class="right">
					<view>更多</view>
					<u-icon name="arrow-right" size="30" color="#999" />
				</view>
			</view>
			<view class="list">
				<swiper class="list" :indicator-dots="false" :autoplay="true" :interval="2500" :duration="500"
				 :display-multiple-items="3">
					<swiper-item v-for="(item, index) in tshopList" :key="index">
						<view class="card">
							<view class="cleft"></view>
							<view class="cright"></view>
							<view class="cright-up"></view>
							<view class="up">
								<text class="tag">￥</text>
								<text class="num">400</text>
							</view>
							<view class="line"></view>
							<view class="down">
								满7000元可用
							</view>
						</view>
					</swiper-item>
				</swiper>
			</view>
		</view> -->

		<!-- 精选推荐 -->
		<view class="ok-chose">
			<view class="title">热门产品</view>
			<view class="puducts">
				<view class="card" v-for="(item, index) in allInfos.selectList" :key="index" @tap="gotoStoreWebView(item.ad_link)">
					<view class="tag cyellow" v-if="item.label_id == 0">{{item.label_name}}</view>
					<view class="tag cblue" v-if="item.label_id == 1">{{item.label_name}}</view>
					<view class="tag cred" v-if="item.label_id == 2">{{item.label_name}}</view>
					<!-- <image class="like" src="../static/lover.png"></image> -->
					<image :src="item.ad_code" mode="aspectFit" class="product-img" />
					<view class="title u-line-2">{{item.ad_title}}</view>
					<view class="info">{{item.ad_subtitle}}</view>
					<view class="price">
						<view class="new-price">￥{{item.shop_price}}</view>
						<view class="old-price" v-if="!!item.market_price && item.market_price < -100">￥{{item.market_price}}</view>
					</view>
				</view>
			</view>
		</view>
		

		<!-- 全部配件 -->
		<!-- <view class="ok-other">
			<view class="title">全部配件</view>
			<view class="puducts">
				<view class="card"  v-for="(item, index) in allInfos.indexList" :key="index" @tap="gotoStoreWebView(item.ad_link)">
					<view class="tag cred" v-if="item.label_id == 0">限时购</view>
					<view class="tag" v-if="item.label_id == 1">热销</view>
					<view class="tag cyellow" v-if="item.label_id == 2">新品</view>
					<image :src="item.ad_code" mode="aspectFit" class="product-img" />
					<view class="title u-line-2">{{item.ad_title}}</view>
					<view class="info">{{item.ad_subtitle}}</view>
					<view class="price">
						<view class="new-price">￥{{item.shop_price}}</view>
						<view class="old-price" v-if="!!item.market_price && item.market_price>=0">￥{{item.market_price}}</view>
					</view>
				</view>
			</view>
		</view> -->
		<!-- 未登录登陆组件 -->
		<login ref="login"></login>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				// 是否显示顶部导航条
				navBarShowTag: true,
				navBarChildShowTag: false,
				scrollTop: 0,
				// 导航快速跳转
				allLinks: [],
				// 页面相关信息
				allInfos: null
			}
		},
		async onShow(){
			// 数据埋点
			this.$$Rangers.event('page_view', {
			    platform: '小程序',
			})
			uni.showTabBar()
			await this.$u.api.checkLogin();
		},
		async onLoad() {
			// 初始化强制唤醒登陆
			this.hasLogin = await this.$u.api.checkLogin();
			// 如果登陆成功后则触发这个方法
			uni.$on("after:login", () => {
				this.$refs.login.close(true);
			});
			this.allLinks = await this.$u.get(this.estoreBaseUrl + "/index.php?m=api&c=Ad&a=getUrlList");
			this.allInfos = await this.$u.get(this.estoreBaseUrl + "/index.php?m=api&c=Ad&a=getIndexConfig");
		},
		onPageScroll(scrollTop) {
			this.scrollTop = scrollTop.scrollTop
			if (this.navBarChildShowTag == true) {
				this.navBarShowTag = false;
				return;
			}
			if (this.scrollTop >= 280) {
				this.navBarShowTag = false;
			} else {
				this.navBarShowTag = true;
			}
		},
		methods: {
			// 打开子栏目
			openChildNav() {
				this.navBarShowTag = false;
				this.navBarChildShowTag = true;
			},
			closeChildNav() {
				if (this.scrollTop >= 280) {
					this.navBarShowTag = false;
				} else {
					this.navBarShowTag = true;
				}
				this.navBarChildShowTag = false;
			},
			// 跳转至商城的 webView
			gotoStoreWebView(url, type) {
				console.log(type)
				if(!!type && type == 'other'){
					uni.navigateTo({
						url: '/pages/webview?url=goToChat',
					});
				}else{
					uni.navigateTo({
						url: '/mine/storeWebView?url=' + encodeURI(url),
					});
				}
				
			}
		}
	};
</script>
